﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CloverNet.Authorization;
using CloverNet.Authorization.Demo.Manager.Providers;

namespace CloverNet.Authorization.Demo.Manager
{
    public class AuthorizationConfig
    {
        public static void Initialization() {

            //获取用户权限
            DefaultPermissionProvider.Current = new LoginPermissionProvider();

            //获取用户-权限
            UserPermissionProvider.Current = new CustomUserPermissionProvider();

            //获取角色-权限
            RolePermissionProvider.Current = new CustomRolePermissionProvider();

            PermissionProviders.Providers.Add(new OtherPermissionProvider());

            //设置无权访问重定向地址
            AuthorizationManager.UnAuthenticationAction = (httpContext) =>
            {
                if (AuthorizationManager.IsLogIn)
                {
                    return new RedirectResult("/Account/UnAuthorization");
                }
                else
                {
                    return new RedirectResult("/Account/LogIn?refer=" + HttpUtility.UrlEncode(httpContext.Request.Url.ToString()));
                }
            };
        }
}
}